﻿using LJ.Abstractions.Pack.Attributes;
using LJ.EventBus.Abstractions.Pack;
using LJ.EventBus.Abstractions;
using LJ.IdGenerator.Abstractions.Pack;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LJ.EventBus.HornedSerpent.Transport.Abstractions.Pack;
using LJ.EventBus.HornedSerpent.Internal;

namespace LJ.EventBus.HornedSerpent.Pack;


[DependPack(typeof(IIdGeneratorPack))]
[DependPack(typeof(IEventBusHornedSerpentTransportPack))]
public abstract class EventBusHornedSerpentPackBase : PackBase, IEventBusPack
{
    public override void Add(IPackContext packContext)
    {

        packContext.ConfigManager.Add<EventBusConfig>("EventBus");

        var eventBusSubscribeManager = new EventBusHandlerManager(packContext.DependencyManager, packContext.ReflectionManager);
        packContext.DependencyManager.ServiceCollection.AddSingleton<IEventBusHandlerManager>(eventBusSubscribeManager);

        packContext.DependencyManager.ServiceCollection.AddSingleton<IEventBusMessageSerializer, EventBusMessageSerializer>();

        packContext.DependencyManager.ServiceCollection.AddTransient<IEventBusSubscribe, EventBusSubscribe>();

        packContext.DependencyManager.ServiceCollection.AddTransient<IEventBusHandlerInvoker, EventBusHandlerInvoker>();

        packContext.DependencyManager.ServiceCollection.AddTransient<IEventBusMessageListener, EventBusMessageListener>();

        packContext.DependencyManager.ServiceCollection.AddScoped<IEventBusPublisher, EventBusPublisher>();


    }

    public override void Use(IPackProvider packProvider)
    {
    }
}
